[HVM] Make grant tables functions work in PV-on-HVM drivers.
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Thu, 17 Aug 2006 15:21:08 +0000 (16:21 +0100)
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Thu, 17 Aug 2006 15:21:08 +0000 (16:21 +0100)
Signed-off-by: Steven Smith <ssmith@xensource.com>
linux-2.6-xen-sparse/drivers/xen/core/gnttab.c
unmodified_drivers/linux-2.6/mkbuildtree
unmodified_drivers/linux-2.6/platform-pci/Kbuild
unmodified_drivers/linux-2.6/platform-pci/platform-pci.c
unmodified_drivers/linux-2.6/platform-pci/platform-pci.h

index a8dc7121099754bf09675f07826fa787ec615930..36e627f60c482071dd0edc789c61d65dcfc6c058 100644 (file)
@@ -41,6 +41,8 @@
 #include <asm/pgtable.h>
 #include <asm/uaccess.h>
 #include <asm/synch_bitops.h>
+#include <asm/io.h>
+#include <xen/interface/memory.h>
 
 /* External tools reserve first few grant table entries. */
 #define NR_RESERVED_ENTRIES 8
@@ -350,6 +352,8 @@ void gnttab_cancel_free_callback(struct gnttab_free_callback *callback)
 }
 EXPORT_SYMBOL_GPL(gnttab_cancel_free_callback);
 
+#ifdef CONFIG_XEN
+
 #ifndef __ia64__
 static int map_pte_fn(pte_t *pte, struct page *pmd_page,
                      unsigned long addr, void *data)
@@ -404,23 +408,57 @@ int gnttab_resume(void)
        shared = __va(frames[0] << PAGE_SHIFT);
        printk("grant table at %p\n", shared);
 #endif
-
-       return 0;
 }
 
 int gnttab_suspend(void)
 {
-
 #ifndef __ia64__
        apply_to_page_range(&init_mm, (unsigned long)shared,
                            PAGE_SIZE * NR_GRANT_FRAMES,
                            unmap_pte_fn, NULL);
 #endif
+       return 0;
+}
+
+#else /* !CONFIG_XEN */
+
+#include <platform-pci.h>
+
+int gnttab_resume(void)
+{
+       unsigned long frames;
+       struct xen_add_to_physmap xatp;
+       unsigned int i;
+
+       frames = alloc_xen_mmio(PAGE_SIZE * NR_GRANT_FRAMES);
+
+       for (i = 0; i < NR_GRANT_FRAMES; i++) {
+               xatp.domid = DOMID_SELF;
+               xatp.idx = i;
+               xatp.space = XENMAPSPACE_grant_table;
+               xatp.gpfn = (frames >> PAGE_SHIFT) + i;
+               if (HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp))
+                       BUG();
+       }
+
+       shared = ioremap(frames, PAGE_SIZE * NR_GRANT_FRAMES);
+       if (shared == NULL) {
+               printk("error to ioremap gnttab share frames\n");
+               return -1;
+       }
 
        return 0;
 }
 
-static int __init gnttab_init(void)
+int gnttab_suspend(void)
+{
+       iounmap(shared);
+       return 0;
+}
+
+#endif /* !CONFIG_XEN */
+
+int __init gnttab_init(void)
 {
        int i;
 
@@ -439,4 +477,6 @@ static int __init gnttab_init(void)
        return 0;
 }
 
+#ifdef CONFIG_XEN
 core_initcall(gnttab_init);
+#endif
index 618b5c594f969c8dc78e9dc16952891ba5f90750..6002b2722d288afce1cec39b9fea0b916a6556f1 100644 (file)
@@ -5,6 +5,7 @@ C=$PWD
 XEN=$C/../../xen
 XL=$C/../../linux-2.6-xen-sparse
 
+ln -sf ${XL}/drivers/xen/core/gnttab.c platform-pci
 ln -sf ${XL}/drivers/xen/core/features.c platform-pci
 
 mkdir -p include
index 0e85e50ff0745464eb50f7e41274fd88639fd45e..a4c1961a8a2bf8c681d2bda3a382c186d851796c 100644 (file)
@@ -4,4 +4,4 @@ obj-m := xen-platform-pci.o
 
 EXTRA_CFLAGS += -I$(M)/platform-pci
 
-xen-platform-pci-objs := evtchn.o platform-pci.o xen_support.o features.o
+xen-platform-pci-objs := evtchn.o platform-pci.o gnttab.o xen_support.o features.o
index 941608d12f019701a40da6d8bd88aad964401b9d..f32399c3cea5166d54890e56ea534bad167db45c 100644 (file)
@@ -64,15 +64,18 @@ static int __init init_xen_info(void)
        xatp.idx = 0;
        xatp.space = XENMAPSPACE_shared_info;
        xatp.gpfn = shared_info_frame;
-       BUG_ON(HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp));
+       if (HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp))
+               BUG();
+
        shared_info_area =
                ioremap(shared_info_frame << PAGE_SHIFT, PAGE_SIZE);
-
-       if (!shared_info_area)
+       if (shared_info_area == NULL)
                panic("can't map shared info\n");
 
        phys_to_machine_mapping = NULL;
 
+       gnttab_init();
+
        return 0;
 }
 
index 8af732c69f9e29dadac45836b7929e1df9ff6536..5e10413b13b95dff34e2453dc35737229855e6e4 100644 (file)
@@ -36,6 +36,8 @@ static inline int set_callback_irq(int irq)
 
 unsigned long alloc_xen_mmio(unsigned long len);
 
+int gnttab_init(void);
+
 void setup_xen_features(void);
 
 irqreturn_t evtchn_interrupt(int irq, void *dev_id, struct pt_regs *regs);